{include file='common/_meta' /}
<style>
.container .layui-form .layui-table .fieldname{
    width:110px;
}
.container .layui-form .layui-table td{
    padding: 5px 8px;

}
.layui-input{
    height: 30px;
    line-height: 32px
}
.container .layui-form .layui-table tr:nth-child(2){
    width: 500px;
}
</style>
<body>
<div class="container">
    <form class="layui-form" action="" lay-filter="form" id="form-article">
    <table class="layui-table" lay-even>
        <tr>
            <td colspan="4" style="padding:8px 10px" ><h2>基本信息：</h2></td>
        </tr>
        <tr>
        <td class="fieldname"><span class="custom-color-red">*</span>公司名称：</td>
        <td colspan="3">
        <input type="text" name="company_name" value="" placeholder="公司名称" autocomplete="off" class="layui-input" lay-verify="required" style="width:200px">
        </td>
        </tr>
        <tr>
            <td class="fieldname"><span class="custom-color-red">*</span>公司联系人：</td>
            <td>
            ******
            <input type="text" name="user_name" value="" placeholder="联系人" autocomplete="off" class="layui-input layui-hide" lay-verify="required" style="width:200px">
            </td>
            <td class="fieldname">联系电话：</td>
            <td>
            ******
            <input style="width:200px" type="text" name="channel_phone" value="" placeholder="联系电话" autocomplete="off" class="layui-input layui-hide">
            
            </td>
        </tr>

        <tr>
            <td>回调接收地址：</td>
            <td><input style="width:100%;" type="text" name="back_url" value="" placeholder="回调接收地址" autocomplete="off" class="layui-input"></td>
        </tr>
    </table>
{if ($info.channel_type=='CMPP')}
<div class="layui-col-xs12">
<div class="layui-col-xs6 ">
<table class="layui-table" lay-even >
    <tr>
        <td colspan="2"><h3>CMPP信息：</h3></td>
    </tr>
    <tr>
    <td>账号：{$channel_cmpp_info.sp_id}</td>
    <td>密码：{$channel_cmpp_info.sp_pwd}</td>
    </tr>
    <tr>
    <td>端口：{$channel_cmpp_info.port}</td>
    <td>速率：{$channel_cmpp_info.sms_limit}</td>
    </tr>
</table>
</div>
</div>
{/if}

<input type="hidden" name="cid" id="cid" value="">
<button style="width:200px" class="layui-btn" lay-submit lay-filter="formDemo">编辑</button>
</form>

</div>
{include file="common/_footer"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
layui.use('form', function() {

    var layer = layui.layer;
    var form  = layui.form;

    form.val("form", {
        "company_name": "{$info.company_name}"
        ,"user_name": "{$info.user_name}"
        ,"cid": "{$info.channel_id}"
    })

    "{$info.channel_type}" == "CMPP" ? $('#is-cmpp').removeClass('layui-hide') : '';

    //监听提交
    form.on('submit(formDemo)', function(data) {
        var indexload = layer.load();
        if(data.field.more_ip == 1)
        {
            if(data.field.connection <= 0)
            {
                layer.msg('请输入多连接数量');
                return false;
            }
        }
        $.ajax({
            type : "POST",
            url  : "{:url('Channel/edt')}",
            data : $("#form-article").serialize(),
            success : function(json) {
                layer.close(indexload);
                if(json.code !== 0) {

                    layer.msg(json.msg, {icon: 5,time:3000});
                    return false;
                } else {

                    layer.msg('编辑成功', {icon:1,time:1000},function(){layer.open({type: 3});parent.location.reload();});
                }
            },
            error : function(e) {
                layer.close(indexload);
                layer.msg('编辑错误', {icon: 5,time:3000});
            }
        });

        return false;
    });
{if condition="session('user_type') == 'admin' "}
    // 监听渠道账号类型
    form.on('select(channel_type)', function(data) {

        if (data.value == 'CMPP') {

            $('#is-cmpp').removeClass('layui-hide');
        } else {

            $('#is-cmpp').addClass('layui-hide');
        }

        form.render();
    });

    //重置加密KEY
    $('form').on('click', '#reset_key', function(event) {

        event.preventDefault();

        layer.confirm('确认要重置key吗？', function(index) {

            $.ajax({
                url: "{:url('Channel/resetKey')}"
                ,type: 'post'
                ,data: {'cid' : $('#cid').val() }
                ,dataType : 'json'
                ,success:function(json) {

                    if (json.code == 1) {

                        layer.msg(json.msg,{
                            icon:2,
                            skin:'layer-ext-moon'
                        });
                    } else {

                        $('#cid_key').val(json.key);
                        $('#key').val(json.key);
                        layer.msg('已重置!', {icon:1, time:1000});
                    }
                }
            });
        });

        form.render();
        return false;
    });
{/if}

});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
